
package com.bbh.plugin.single.privilege.demo.controller.mail;

import com.bbh.plugin.single.privilege.demo.controller.BasicController;
import com.bbh.common.base.vo.GridVo;
import com.bbh.common.domain.Condition;
import com.bbh.common.domain.Page;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * Controller - 邮件管理
 *
 * @author ZHANGTYONG
 * @version 3.0
 */
@Controller
@RequestMapping("/mail/info")
public class MailInfoController extends BasicController {

//    @Autowired
//    private MongoResource mongoService;

    /**
     * 跳转到邮件查询首页
     *
     * @author ZHANGYONG
     */
    @RequestMapping(value = VIEW_FILED + "/index", method = RequestMethod.GET)
    public String index(ModelMap model) {
//        model.addAttribute("mailTypeItems", EnumSet.allOf(MailEnum.MAIL_TYPE.class));
        return "single/mail/index";
    }

    /**
     * 邮件列表
     *
     * @param request
     * @param subject   邮件主题
     * @param startTime 发送时间起
     * @param endTime   发送时间止
     * @param mailType  邮件发送类型
     * @return
     * @throws org.springframework.web.bind.ServletRequestBindingException
     */
    @RequestMapping(value = VIEW_FILED + "/list")
    @ResponseBody
    public GridVo list(HttpServletRequest request, String subject, Date startTime, Date endTime, String mailType) throws Exception {
        Condition params = new Condition();
        if (StringUtils.isNotBlank(subject)) {
            params.put("subject", subject);
        }
        if (null != startTime) {
            params.put("startTime", startTime);
        }
        if (null != endTime) {
            params.put("endTime", endTime);
        }
        if (StringUtils.isNotBlank(mailType)) {
            params.put("mailType", mailType);
        }
        GridVo vo = new GridVo();
        Page pageRequest = initPageRequest(request, PAGE_NUMBER, PAGE_ROWS);
//        Page page = new Page<MailInfoVo>(pageRequest.getPageNum() + 1, pageRequest.getPageSize());
//        Page<?> pageResult = mongoService.getMailInfoByCondition(params, page);
//        if (pageResult != null) {
//            vo.setRows(pageResult.getList());
//            vo.setTotal(pageResult.getPages());//总页数
//            vo.setRecords(pageResult.getTotal());//总记录数
//            if (pageResult.getList().size() <= 0) {
//                vo.setPage(0);//当前页
//            }
//        }
        return new GridVo(pageRequest);
    }


}